function uStrlen(s){
	var ret = 0;
	for (var i = 0; i < s.length; i ++){
		if (s.charCodeAt(i) > 127) ret += 2;
		else ret ++;
	}
	return ret;
}

function isValidMobile(mobile){
	if (uStrlen(mobile) != 11) return false;
	for (var i = 0; i < mobile.length; i ++)
		if (mobile[i] < '0' || mobile[i] > '9') return false;
	if (mobile < "13000000000" || mobile > "19000000000") return false;
	return true;
}

function isValidFidocard(fidocard){
	if (uStrlen(fidocard) != 13) return false;
	for (var i = 0; i < fidocard.length; i ++)
		if (fidocard[i] < '0' || fidocard[i] > '9') return false;
	return true;
}
	
function isValidName(username){
	if (uStrlen(username) < 4 || uStrlen(username) > 16) return false;	
	for (var i = 0; i < username.length; i ++){
		var c = username.charCodeAt(i);
		if (!((c <= 0x9fff && c >= 0x4e00) || (c >= 48 && c <= 57)  || (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c == 32)) return false;
	}
	return true;
}

function isValidPassword(password){
	if (password.length < 6 || password.length > 16) return false;
	for (var i = 0; i < password.length; i ++){
		var c = password.charCodeAt(i);
		if (!((c >= 48 && c <= 57) || (c >= 65 && c <= 90) || (c >= 97 && c <= 122) || c == 95 || c == 32)) return false;
	}
	return true;
}

function isValidEmail(email){
	regExp = /^[a-zA-Z]+([_\.-]?[a-zA-Z0-9]+)*@[a-zA-Z0-9]+([\.-]?[a-zA-Z0-9]+)*(\.[a-zA-Z]{2,4})+$/;
	return email.search(regExp) != -1;
} 

function trimContent(text){
	text = text.replace(new RegExp("&", "g"), "&amp;");
	text = text.replace(new RegExp(" ", "g"), "&nbsp;");
	text = text.replace(new RegExp("<", "g"), "&lt;");
	text = text.replace(new RegExp(">", "g"), "&gt;");
	text = text.replace(new RegExp("\"", "g"), "&quot;");
	text = text.replace(new RegExp("\r\n", "g"), "<br/>");
	text = text.replace(new RegExp("\n", "g"), "<br/>");
	text = text.replace(new RegExp("<br/><br/>", "g"), "<br/>");
	return text;
}